
$(document).ready(function(){
    randomBackground();
    generateMap();

    //nav responsive
    $("#hamburger-icon").click(function(){
        if (!$(this).hasClass("active")) {
            $(this).addClass("active");
            $("ul#nav-responsive").fadeIn();
        } else {
            $(this).removeClass("active");
            $("ul#nav-responsive").fadeOut();
        }
    });

    $("#wrapper").fadeIn("slow");

    $(".thumb").each(function(index){
        var count = index + 1;
        var targetItem = count%6;
        if(targetItem == 0){
            $(this).addClass("last");
        }
    });

    $(".gallery1").fancybox({
        openEffect  : 'none',
        closeEffect : 'none'
    });
});

function randomBackground(){
	if(index != true)
	{
		var images = ['image2.jpg','image3.jpg','image4.jpg'];
		$('html').css({'background-image': 'url(' + rootUrl + 'images/' + images[Math.floor(Math.random() * images.length)] + ')'});
	}else{
        $('html').css({'background-image': 'url(' + rootUrl +'images/test.jpg'});
    }
}

function validateForm(){
    var error = 0;

    $(".contact-input").each(function(){
        if($(this).attr("id") == "name")
        {
            if($(this).val() == "")
            {
                error++;
                $("#error-name").fadeIn();
            }else{
               $("#error-name").fadeOut(); 
            }
        }else if($(this).attr("id")== "email"){
            if($(this).val() == "")
            {
                error++;
                $("#error-format").fadeOut(function(){
                    $("#error-email").fadeIn();
                });
            }else if($(this).val() != ""){

                var str = $(this).val();
                var filter = /^([a-zA-Z0-9_\.\-\'])+\@(([a-zA-Z0-9\-\_])+\.)+([a-zA-Z0-9]{2,4})+$/;
                if (!filter.test(str)) {
                      $("#error-email").fadeOut(function(){
                        $("#error-format").fadeIn();
                      });
                        error++;
                    } else {
                        $("#error-format").fadeOut();
                    }
            }
        }else if($(this).attr("id") == "message"){
            if($(this).val() == ""){
                $("#error-message").fadeIn();
                error++;
            }else{
               $("#error-message").fadeOut(); 
            }
        }
    });

    if(error == 0){
        sendEmail();
    }
}


function sendEmail(){
    
}

function generateMap(){
    //google map
             // When the window has finished loading create our google map below
            google.maps.event.addDomListener(window, 'load', init);
        
            function init() {
                var map1Coord = new google.maps.LatLng(45.9710903, -74.3382771);// 1950 Ch. du Village , St-Adolphe-d’Howard J0T 2B0
                var map2Coord = new google.maps.LatLng(45.8937558, -74.1580196);// 260 Rue Principale, Saint-Sauveur, QC J0R 1R0, Canada
                var zoom = 19;
                var style = [{featureType:"road",elementType:"geometry",stylers:[{lightness:100},{visibility:"simplified"}]},{"featureType":"water","elementType":"geometry","stylers":[{"visibility":"on"},{"color":"#C6E2FF",}]},{"featureType":"poi","elementType":"geometry.fill","stylers":[{"color":"#C5E3BF"}]},{"featureType":"road","elementType":"geometry.fill","stylers":[{"color":"#D1D1B8"}]}];
                var image = rootUrl + 'images/marker.png';

                //shop1
                var mapOptions1 = {
                    zoom: zoom,
                    center: map1Coord, 
                    styles: style
                };

                //shop 2
                var mapOptions2 = {
                    zoom: zoom,
                    center: map2Coord,
                    styles: style
                };
                // Create the Google Map using out element and options defined above
                var map1 = new google.maps.Map(document.getElementById('map1'), mapOptions1);
                var map2 = new google.maps.Map(document.getElementById('map2'), mapOptions2);

                //marker
                    var marker1 = new google.maps.Marker({
                        position: map1Coord,
                        map: map1,
                        icon: image
                    });

                
                    var marker2 = new google.maps.Marker({
                        position: map2Coord,
                        map: map2,
                        icon: image
                    });
            }
}
